package vikaa.timelinepackage;

import java.util.ArrayList;

import vikaa.bean.WowoTwitter_item;
import vikaa.tools.HttpUtil;
import vikaa.tools.ValueClass;
import vikaa.wowo.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class AdapterTwitters extends BaseAdapter{//display weibo gridview adapter
	private Context context;
	private LayoutInflater inflater;
	private final ArrayList<WowoTwitter_item>  mlist; 
	public AdapterTwitters(Context context, LayoutInflater inflater, ArrayList<WowoTwitter_item> wbList) {
		super();
		this.context = context;
		this.inflater = inflater;
		this.mlist = wbList;
	}
	public int getCount() {
		return mlist.size();
	}

	public Object getItem(int position) {
		return mlist.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		Holder wh;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.photolist_item, null);
			wh = new Holder();
	        wh.pic = (ImageView) convertView.findViewById(R.id.photolist_item);
	        wh.selectImg = (ImageView) convertView.findViewById(R.id.select);
	        convertView.setTag(wh);
		}else{
			wh = (Holder)convertView.getTag();
		}
		WowoTwitter_item twitter = mlist.get(position);
		if(twitter.getThumbnail_pic().length()<5){
			wh.pic.setImageResource(R.drawable.select_image_default);
		}
		else{
			AsyLoadImg.loadGridviewPhoto(HttpUtil.HttpUrlComplete(twitter.getThumbnail_pic()), wh.pic,twitter.isSelected(),context,TimelineImportWeibo.role,twitter.isState());
		}
		if(twitter.isSelected()){
			if(Integer.valueOf(TimelineImportWeibo.role) == ValueClass.ROLE_ADMIN || Integer.valueOf(TimelineImportWeibo.role) == ValueClass.ROLE_CREATOR || twitter.isState()){
				wh.selectImg.setImageResource(R.drawable.photo_selected);
			}else{
				wh.selectImg.setImageResource(R.drawable.photo_state);
			}
		}else{
			wh.selectImg.setImageResource(R.drawable.photo_unselected);
		}
		return convertView;
	}
	static class Holder {
    	public ImageView pic = null;
    	public ImageView selectImg = null;
    }
	public void changeState(int position,View view){
		mlist.get(position).setSelected(!(mlist.get(position).isSelected()));
    	notifyDataSetChanged();
    }
}
